﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using CyclicReferences.Public;
using Domain;
using System.Reflection;

namespace Interfaces
{
    [CircularReferenceSurrogateAttribute]
    [ServiceContract(Namespace = "Http://sitechno.Employee")]
    [ServiceKnownType("GetKnownTypes", typeof(KnownTypeHelper))]
    public interface IEmployeeService
    {
        [OperationContract]
        List<Employee> GetEmployees(string lastNameBeginsWith);

        [OperationContract]
        Person SavePerson(Person person);

        [OperationContract]
        Employee GetEmployee(int id);


    }

    static class KnownTypeHelper
    {
        public static IEnumerable<Type> GetKnownTypes(ICustomAttributeProvider provider)
        {
            List<Type> knownTypes = new List<Type>();
            foreach (Type t in typeof(Person).Assembly.GetTypes())
                if (t.Name.EndsWith("Surrogate"))
                { knownTypes.Add(t); }

            return knownTypes;
        }

    }
}
